package dao.impl;


import dao.DeptDao;
import entity.Dept;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

public class DeptDaoImpl implements DeptDao {

    private QueryRunner query;

    public QueryRunner getQuery() {
        return query;
    }

    public void setQuery(QueryRunner query) {
        this.query = query;
    }

    @Override
    public String getNameById(Integer id) {

        QueryRunner qr = getQuery();
        String sql = "select deptname  from dept where id = ?";
        BeanHandler<Dept> handler = new BeanHandler<>(Dept.class);
        Dept dept = null;
        try {
            dept = qr.query(sql, handler, id);
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return dept.getDeptname();
    }


}
